package com.weilun.controller;

import com.weilun.mapper.EmpExprMapper;
import com.weilun.pojo.Emp;
import com.weilun.pojo.EmpQueryParam;
import com.weilun.pojo.PageResult;
import com.weilun.pojo.Result;
import com.weilun.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;

@Slf4j
@RequestMapping("/emps")
@RestController
public class EmpController {

    @Autowired
    private EmpService empService;


    /*
    分页查询
    */
   //@GetMapping
    /*    public Result page(@RequestParam(defaultValue = "1") Integer page ,
                       @RequestParam(defaultValue = "10") Integer pageSize){
        log.info("查询员工信息, page={}, pageSize={}",page,pageSize);
        //log.info("查询员工信息, page={}, pageSize={}", page, pageSize);
        PageResult pageResult = empService.page(page, pageSize);
        return Result.success(pageResult);
        }*/
    /*
    条件分页查询
    */
    @GetMapping
    public Result page(EmpQueryParam empQueryParam){
        log.info("条件分页查询, {}",empQueryParam);
        PageResult pageResult = empService.page(empQueryParam);
        return Result.success(pageResult);
    }

    /**
     * 查询回显
     */
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
        log.info("根据id查询员工的详细信息");
        Emp emp  = empService.getInfo(id);
        return Result.success(emp);
    }

    /**
     * 更新员工信息
     */
    @PutMapping
    public Result update(@RequestBody Emp emp){
        log.info("修改员工信息, {}", emp);
        empService.update(emp);
        return Result.success();
    }

    /*
    * 新增员工
    * */
    @PostMapping
    public Result save(@RequestBody Emp emp){
        log.info("新增员工, {}",emp);
        empService.save(emp);
        return Result.success();
    }

    /*
    * 删除员工
    * */
    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){
        log.info("根据id删除员工：{}", ids);
        empService.delete(ids);
        return Result.success();
    }
}
